<!-- 单行模型 -->
<template>
  <div class="model-item" :class="{ 'can-click': hasDetail(type) }" @click.stop="goModelDetail(model)">
    <div class="name elliptical-1" :title="model?.cn">{{ model?.cn }}</div>
    <div class="flex-1"></div>
    <div class="model-type">{{ type }}</div>
  </div>
</template>

<script lang="ts" setup>
  import { computed } from 'vue'

  const ModelTypeMap: { [key in number]: string } = {
    1: 'CHECKPOINT',
    2: 'LORA',
    3: 'EMBEDDING'
  }
  export interface Props {
    model: any
  }

  const props = withDefaults(defineProps<Props>(), {})

  const type = computed(() => {
    return ModelTypeMap?.[props?.model?.type as number]
  })

  const hasDetail = (type: string) => {
    return ['CHECKPOINT', 'LORA'].includes(type)
  }

  const goModelDetail = (model: any) => {
    if (hasDetail(model.type)) {
      location.href = `/model-detail/${model.modelId}`
    }
  }
</script>

<style lang="less" scoped>
  .model-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    height: 38px;
    background: #fff;
    border: 1px solid #d9d9db;
    border-radius: 6px;
    align-self: stretch;

    .name {
      width: 270px;
      font-size: 14px;
      color: rgba(21, 23, 27, 0.95);
      font-style: normal;
      font-weight: 400;
      line-height: 22px;
    }

    .model-type {
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 7px 10px;
      margin-left: 4px;
      height: 23px;
      font-size: 12px;
      text-align: center;
      color: #4686ed;
      background: rgba(70, 134, 237, 0.08);
      border: 1px solid rgba(0, 0, 0, 0.05);
      border-radius: 12px;
      gap: 2px;
      line-height: 20px;
    }

    .iconfont {
      color: rgba(17, 22, 31, 0.29);
    }

    &.can-click {
      cursor: pointer;
    }
  }
</style>
